package utils;

import java.util.Arrays;
import java.util.Comparator;

public class lambda2 {
    public static void main(String[] args) {
        String[] players = {"Rafael Nadal", "Novak Djokovic",
                "Stanislas Wawrinka", "David Ferrer",
                "Roger Federer", "Andy Murray",
                "Tomas Berdych", "Juan Martin Del Potro",
                "Richard Gasquet", "John Isner"};
        for (String play :
                players) {
            System.out.print(play+"     ");
        }
        System.out.println();
        //传统排序
        Arrays.sort(players,new Comparator<String>(){
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        for (String play :
                players) {
            System.out.print(play+"     ");
        }
        System.out.println();
        //lambda排序1
        Comparator<String> comparator = (o1,o2) -> o1.compareTo(o2);
        Arrays.sort(players,comparator);
        //lambda排序2
        Arrays.sort(players,(o1,o2) -> o1.compareTo(o2));
    }
}
